package com.oa.demo.server.system.service.impl;

import com.oa.demo.server.system.entity.TAuthMenu;
import com.oa.demo.server.system.mapper.TAuthMenuMapper;
import com.oa.demo.server.system.service.ITAuthMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import com.oa.demo.common.exception.BaseAuthException;

/**
* <p>
*  服务实现类
* </p>
*
* @author kongbox
* @since 2020-11-30
*/
@Slf4j
@Service
public class TAuthMenuServiceImpl extends ServiceImpl<TAuthMenuMapper, TAuthMenu> implements ITAuthMenuService {

    @Override
    public Page<TAuthMenu> listTAuthMenusByPage(int page, int pageSize, String factor) {
    log.info("正在执行分页查询tAuthMenu: page = {} pageSize = {} factor = {}",page,pageSize,factor);
    QueryWrapper<TAuthMenu> queryWrapper =  new QueryWrapper<TAuthMenu>().like("", factor);
    //TODO 这里需要自定义用于匹配的字段,并把wrapper传入下面的page方法
    Page<TAuthMenu> result = super.page(new Page<>(page, pageSize));
    log.info("分页查询tAuthMenu完毕: 结果数 = {} ",result.getRecords().size());
    return result;
    }

    @Override
    public TAuthMenu getTAuthMenuById(int id) {
    log.info("正在查询tAuthMenu中id为{}的数据",id);
    TAuthMenu tAuthMenu = super.getById(id);
    log.info("查询id为{}的tAuthMenu{}",id,(null == tAuthMenu?"无结果":"成功"));
    return tAuthMenu;
    }

    @Override
    public int insertTAuthMenu(TAuthMenu tAuthMenu) throws BaseAuthException {
    log.info("正在插入tAuthMenu");
    if (super.save(tAuthMenu)) {
    log.info("插入tAuthMenu成功,id为{}",tAuthMenu.getId());
    return tAuthMenu.getId();
    } else {
    log.error("插入tAuthMenu失败");
    throw new BaseAuthException("添加失败");
    }
    }

    @Override
    public int deleteTAuthMenuById(int id) throws BaseAuthException {
    log.info("正在删除id为{}的tAuthMenu",id);
    if (super.removeById(id)) {
    log.info("删除id为{}的tAuthMenu成功",id);
    return id;
    } else {
    log.error("删除id为{}的tAuthMenu失败",id);
    throw new BaseAuthException("删除失败[id=" + id + "]");
    }
    }

    @Override
    public int updateTAuthMenu(TAuthMenu tAuthMenu) throws BaseAuthException {
    log.info("正在更新id为{}的tAuthMenu",tAuthMenu.getId());
    if (super.updateById(tAuthMenu)) {
    log.info("更新d为{}的tAuthMenu成功",tAuthMenu.getId());
    return tAuthMenu.getId();
    } else {
    log.error("更新id为{}的tAuthMenu失败",tAuthMenu.getId());
    throw new BaseAuthException("更新失败[id=" + tAuthMenu.getId() + "]");
    }
    }

    }
